/*
 * SearchWebBean.java
 *
 * Created on May 15, 2007, 11:24 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.vce.web;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 *
 * @author lruiz
 */
public class SearchManagedBean extends ManagedBean{
    private Collection results;
    private Object result;
    private Object criteria;
    private String criteriaClassname;
    
    /** Creates a new instance of SearchWebBean */
    public SearchManagedBean() {
    }
    
    public void setCriteriaClassname(String criteriaClassname){
        this.criteriaClassname = criteriaClassname;
    }
    
    public Object getCriteria(){
        if(criteria == null && criteriaClassname != null){
            setup();
        }
        return criteria;
    }
    
    public Collection getResults(){
        return results;
    }
    
    public void setResults(Collection results){
        if(results instanceof List || results == null){
            this.results = results;
        }else{
            this.results = new ArrayList(results);
        }
    }
    
    public void setup(){
        try{
            Class clazz = Class.forName(criteriaClassname);
            criteria = clazz.newInstance();
        }catch(Exception e){
            throw new RuntimeException(e);
        }
        
    }
    
    @Override
    public String startup(){
        setup();
        return "success";
    }
    
    public void search(){
        
    }
    
    @Override
    public void reset(){
        results = null;
    }
    
    @Override
    public String cancel(){
        results = null;
        return "cancel";
    }
}
